package com.zhou;

import java.util.Scanner;

/**
 * T14
 * 三个面，以及一圈数字，
 *
 * @author zhouxianfeng
 * @date 2021-8-23
 */
public class T14 {

    private static int[][] map = new int[][]{
            {0, 1, 3, 2, 22, 9, 7, 5, 23, 8, 6, 4},
            {6, 7, 13, 12, 2, 8, 17, 11, 3, 14, 16, 5},
            {4, 5, 11, 10, 0, 6, 16, 20, 2, 12, 18, 22}
    };

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int attempts = 5;
        int[] m = new int[24];
        for (int i = 0; i < 24; i++) {
            m[i] = sc.nextInt();
        }
        System.out.println(resolve(m, -1, attempts));
    }

    private static int resolve(int[] n, int type, int remind) {
        if (remind < 0) {
            return Integer.MIN_VALUE;
        }
        int max = compute(n);
        if (type != 0)
            max = Math.max(max, ops(n, 0, remind));
        if (type != 1)
            max = Math.max(max, ops(n, 1, remind));
        if (type != 2)
            max = Math.max(max, ops(n, 2, remind));
        return max;
    }

    private static int ops(int[] n, int type, int remind) {
        int max = Integer.MIN_VALUE;
        //第一次移动
        move(n, type);
        if (remind >= 1) max = Math.max(max, resolve(n, type, remind - 1));
        //第二次移动
        move(n, type);
        if (remind >= 2) max = Math.max(max, resolve(n, type, remind - 2));
        //第三次移动，相当于反向移动一次
        move(n, type);
        if (remind >= 1) max = Math.max(max, resolve(n, type, remind - 1));
        //第四次移动，相当于不动
        move(n, type);
        return max;
    }

    private static void move(int[] n, int type) {
        int temp = 0;
        for (int i = 0; i < 12; i++) {
            if (i % 4 == 0)
                temp = n[map[type][i]];

            if (i % 4 == 3)
                n[map[type][i]] = temp;
            else
                n[map[type][i]] = n[map[type][i + 1]];
        }
    }


    /**
     * 计算当前状态的优美度
     *
     * @param n 当前状态
     * @return 优美度
     */
    private static int compute(int[] n) {
        return n[0] * n[1] * n[2] * n[3] +
                n[6] * n[7] * n[12] * n[13] +
                n[4] * n[5] * n[10] * n[11] +
                n[8] * n[9] * n[14] * n[15] +
                n[16] * n[17] * n[18] * n[19] +
                n[20] * n[21] * n[22] * n[23];
    }

}
